/*
 * Data.cpp
 *
 *  Created on: 2010-7-15
 *      Author: zhzuo
 */

#include "Data.h"

DataRow::DataRow(){
	this->ColumnsCount=0;
	//this->vec=new QVector<QPair>();
}

QVariant& DataRow::operator [](const QString& k){
	QPair<QString,QVariant> p;
	for(int i=0;i<this->vec.size();i++)
	{
		p=this->vec[i];
		if(p.first.trimmed().toLower()==k.trimmed().toLower()){
			return p.second;
		}
	}
}

QVariant& DataRow::operator [](const int i){
	return this->vec[i].second;
}

QVariant& DataRow::get(const QString& k){
	QPair<QString,QVariant> p;
	for(int i=0;i<this->vec.size();i++)
	{
		p=this->vec[i];
		if(p.first.trimmed().toLower()==k.trimmed().toLower()){
			return p.second;
		}
	}
}

QVariant& DataRow::get(const int i){
	return this->vec[i].second;
}

QString DataRow::ColumnName(const int i){
	return this->vec[i].first;
}

void DataRow::Append(QPair<QString,QVariant> p){
	QPair<QString,QVariant> v=p;
	this->vec.append(v);
	this->ColumnsCount++;
}

DataTable::DataTable(){
	this->RowsCount=0;
	this->ColumnsCount=0;
}

DataRow& DataTable::operator [](const int i){
	return this->vec[i];
}

DataRow& DataTable::get(const int i){
	return this->vec[i];
}

void DataTable::Append(DataRow& dr){
	this->vec.append(dr);
	this->RowsCount++;
	this->ColumnsCount=dr.ColumnsCount;
}

QString DataTable::ColumnName(const int i){
	if(this->RowsCount<1){
		return "";
	}
	DataRow dr=this->vec[i];
	return dr.ColumnName(i);
}
